package com.itheima.handler;

import com.itheima.R;
import com.itheima.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public R ex(Exception e){
      log.info(e.getMessage());
      return R.error(e.getMessage());
    }
    @ExceptionHandler(BusinessException.class)
    public R ex(BusinessException e){
        log.info(e.getMessage());
        return R.error(e.getMessage());
    }
}
